package com.example.RemindMe;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.jBCrypt.BCrypt;


public class DialogActivity extends Activity {

   public static boolean noteActvityStarted = false;


    //Button activity_login
    private Button bOk2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //load SharedPref
        SharedPreferences sharedPreferences = getSharedPreferences("registrationScreen", MODE_PRIVATE);
        Boolean registrationSetting = sharedPreferences.getBoolean("registrationSetting",true);

        if(registrationSetting == false){

           setContentView(R.layout.activity_login);

            TextView linkToReset = (TextView) findViewById(R.id.link_to_reset);
            linkToReset.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent i = new Intent(getApplicationContext(), PWResetActivity.class);
                    startActivity(i);
                    finish();
                }
            });
            bOk2 = (Button) findViewById(R.id.bOk2);

        }else
        {
            //test=true;
            Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
            startActivity(i);
            finish();
        }
    }

    //Method activity_login
    public void dialogButton2(View view){

        switch (view.getId()){

            case R.id.bOk2:
                EditText eText = (EditText) findViewById(R.id.ePassword);
                String pwEditText = eText.getText().toString();

                SharedPreferences sharedPreferences = getSharedPreferences("passwordEncrypted", MODE_PRIVATE);

                if(BCrypt.checkpw(pwEditText, sharedPreferences.getString("pw","DEFAULT"))){
                    //If password correct, start Note activity
                    noteActvityStarted=true;
                    startActivity (new Intent(getApplicationContext(), NoteActivity.class));
                    finish();
                } else {
                    TextView textView = (TextView) findViewById(R.id.dText2);
                    textView.setText("Password Wrong, Retype:" );
                }
                break;

            case R.id.bCancel2:
                finish();
                break;
        }
    }

}
